from openai import OpenAI

from api.fm.configs import ConfigManager


class LLM:
    GPT_4O_AUDIO_PREVIEW = "gpt-4o-audio-preview"
    GPT_4 = "gpt-4"
    GPT_4O = "gpt-4o"
    GPT_4O_2024_05_13 = "gpt-4o-2024-05-13"
    GPT_4O_2024_08_06 = "gpt-4o-2024-08-06"
    GPT_4O_2024_11_20 = "gpt-4o-2024-11-20"
    CHATGPT_4O_LATEST = "chatgpt-4o-latest"
    GPT_4O_MINI = "gpt-4o-mini"
    GPT_4O_MINI_2024_07_18 = "gpt-4o-mini-2024-07-18"
    GPT_4_TURBO = "gpt-4-turbo"
    GPT_4_TURBO_2024_04_09 = "gpt-4-turbo-2024-04-09"
    GPT_4_TURBO_PREVIEW = "gpt-4-turbo-preview"

    def __init__(self, config_manager: 'ConfigManager'):
        self.config = config_manager.get_config()

        self.client = OpenAI(
            api_key=self.config.get("OPENAI_API_KEY"),
            base_url=self.config.get("OPENAI_API_BASE_URL"),
        )

    def easy_chat(self, txt, model):
        msg = [
            {'role': 'system', 'content': "一步一步来，准确的解答"},
            {'role': 'user', 'content': f"{txt}"}
        ]
        response = self.client.chat.completions.create(
            model=model,
            messages=msg,
            stream=False,
        )
        return response.choices[0].message.content
